import { webToPdf, convertToReadingMode, pure } from "./lib/puppeteer.js";

import { glob } from "glob";

import path from "path";

import fsPromises from "fs/promises";

(async () => {
  await main();
})();

async function main() {
  let files = await glob(`D:/研判知识库压缩包/潇湘信安/**/*.html`);

  const index = Number(await fsPromises.readFile("./config.txt", "utf-8")) || 0;

  console.log("初始化index", index);

  for (let i = index; i < files.length; i++) {
    const url = `file://${files[i]}`;
    const fileName = path.basename(files[i], ".html") + ".pdf";

    await webToPdf(url, {
      dir: "output",
      fileName: fileName,
    });

    await new Promise((resolve) => setTimeout(resolve, 1000 * 5));

    await fsPromises.writeFile("./config.txt", i.toString());
  }
}
